package com.hfh.learn;

/**
 * @Author hfh
 * @Date 2022 09 14 20 32
 **/
public class Worker implements Cloneable{
    private String name;
    private int age;
    private Address address;

    public static void main(String[] args) throws Exception {
        Worker worker = new Worker();
        Address address = new Address();
        address.setDetail("合肥");
        worker.name = "赵四";
        worker.age = 11;
        worker.address = address;

        Object obj = worker.clone();
        Worker cloneWor = (Worker) obj;
        System.out.println(System.identityHashCode(worker));
        System.out.println(System.identityHashCode(cloneWor));

        System.out.println(worker.name);
        System.out.println(cloneWor.name);
        // 浅克隆, 克隆的引用数据类型指向同一个堆内存的地址值
        System.out.println(System.identityHashCode(worker.address));
        System.out.println(System.identityHashCode(cloneWor.address));
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public Address getAddress() {
        return address;
    }

    public void setAddress(Address address) {
        this.address = address;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
